package com.leetcode.LC;

public class LC461 {
    public int hammingDistance(int x, int y) {

        StringBuilder a = new StringBuilder(Integer.toBinaryString(x));
        StringBuilder b = new StringBuilder(Integer.toBinaryString(y));
        a.reverse();
        b.reverse();
        System.out.print(a + "\n" + b);
        System.out.println();
        int count = 0, m = 0, n = 0;
        while (m < a.length() || n < b.length()) {

            if (m < a.length() && n < b.length()) {
                if (a.charAt(m) != b.charAt(n)) {
                    count++;
                }
                m++;
                n++;
            } else if (m < a.length()) {
                if (a.charAt(m) == '1') {
                    count++;
                }
                m++;
            } else {
                if (b.charAt(n) == '1') {
                    count++;
                }
                n++;
            }
        }
        return count;
    }

    public static void main(String[] args) {

        System.out.println(new LC461().hammingDistance(1, 4));
    }
}
